<template>
  <div>
    <div id="navButtonLeft">
          <el-button type="warning" @click="goBack">返回</el-button>
          <el-button type="primary" @click="checkRecord">查看日志</el-button>
    </div>
    <div id="navButtonRight">
      <el-button type="danger"@click="GeneratePdf(htmlTitle)" >导出PDF</el-button>
    </div>
    <table align="center" width="700" border="2px"  bordercolor="#000000" cellpadding="3">
      <table id="pdfGen" align="center" width="700">
       <h1 align="center"><strong>辽东学院教育教学改革与研究项目 </strong></h1>
       <h2 align="center"><strong>申   请   表 </strong></h2>
       <p align="center">&nbsp;</p>
       <p align="center">&nbsp;</p>
       <p align="center">&nbsp;</p>
       <p align="center">&nbsp;</p>
       <p align="center">&nbsp;</p>
       <table width="500" height="276" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000">
       	<tr>
       		<td>项目名称：</td>
       		<td>{{project.proName}}</td>
       	</tr>
       	<tr v-for="(item,index) in members" v-if="index==0">
       		<td>项目主持人：</td>
       		<td>{{item.memberName}}</td>
       	</tr>
       	<tr>
       		<td>所属类别：</td>
       		<!-- <td>{{getCategory()}}</td> -->
       	</tr>
       	<tr>
       		<td>所在单位：</td>
       		<td>{{project.proDepartment}}</td>
       	</tr>
       	<tr>
       		<td>电话（办）：</td>
       		<td>{{project.proTelephone}}</td>
       	</tr>
       	<tr>
       		<td>E-mail：</td>
       		<td>{{project.proEmail}}</td>
       	</tr>
       	<tr>
       		<td>填表日期：</td>
       		<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;年&nbsp;&nbsp;&nbsp;&nbsp;月&nbsp;&nbsp;&nbsp;&nbsp;日</td>
       	</tr>
       	</table>
       <p align="center">&nbsp;</p>
       <p align="center">&nbsp;</p>
       <p align="center">&nbsp;</p>
       <p align="center">&nbsp;</p>
       <p align="center">&nbsp;</p>
       <p align="center"><strong>辽东学院教务处</strong></p>
       <p align="center">&nbsp;</p>
       <p align="center">&nbsp;</p>
       <p align="center">&nbsp;</p>
       <p align="center">&nbsp;</p>
       <p align="center">&nbsp;</p>
       <p align="center">&nbsp;</p>
       <p align="center">&nbsp;</p>
       <p>&nbsp;</p>
       					<p align="left">一、基本情况 </p>
       <table width="650" height="900" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000" class="SongFont">
       <tr>
       	<td colspan="2" align="center" valign="middle">项目名称</td>
       	<td colspan="11" align="center" valign="middle">{{project.proName}}</td>
       </tr>
       <tr>
       	<td colspan="2" align="center" valign="middle">所属类别</td>
       	<!-- <td colspan="11" align="center" valign="middle">{{getCategory()}}</td> -->
       </tr>
       <tr>
       	<td colspan="2" align="center" valign="middle">起止年月</td>
       	<td colspan="11" align="center" valign="middle">{{nowDate}}至{{project.proEnddate}}</td>
       </tr>
       <tr v-for="(item,index) in members" v-if="index==0">
       	<td width="19" rowspan="13" align="center" valign="middle"><p>项</p>
       	<p>目</p>
       	<p>主</p>
       	<p>持</p>
       	<p>人</p>
         </td>
       	<td width="65" align="center" valign="middle">姓 名</td>
       	<td colspan="3" align="center" valign="middle">{{item.memberName}}</td>
       	<td width="36" align="center" valign="middle">性<br />
       	别</td>
       	<td width="28" align="center" valign="middle">{{Sex}}</td>
       	<td width="49" align="center" valign="middle">职称</td>
       	<td width="69" align="center" valign="middle">{{item.memberTitle}}</td>
       	<td width="45" align="center" valign="middle">现 任职 务</td>
       	<td colspan="3" align="center" valign="middle">{{item.memberJob}}</td>
       </tr>
       <tr>
       	<td rowspan="6" align="center" valign="middle"><p align="center">主要教学工作简历 </p></td>
       	<td colspan="4" align="center" valign="middle">时间</td>
       	<td colspan="3" align="center" valign="middle">课程名称</td>
       	<td align="center" valign="middle">授 课对 象</td>
       	<td width="30" align="center" valign="middle">学时</td>
       	<td colspan="2" align="center" valign="middle">所在单位</td>
       </tr>
       <tr v-for="rAD in teachings">
       	<td colspan="4" align="center" valign="middle">{{rAD.teachingDateStart}}至{{rAD.teachingDateEnd}}</td>
       	<td colspan="3" align="center" valign="middle">{{rAD.teachingCoursename}}</td>
       	<td align="center" valign="middle">{{rAD.teachingPrelectobject}}</td>
       	<td align="center" valign="middle">{{rAD.teachingLearnhour}}</td>
       	<td colspan="2" align="center" valign="middle">{{rAD.teachingDepartment}}</td>
       </tr>
       <tr v-for="rowNumber in 5 - teachings.length">
       	<td colspan="4" align="center" valign="middle">&nbsp;</td>
       	<td colspan="3" align="center" valign="middle">&nbsp;</td>
       	<td align="center" valign="middle">&nbsp;</td>
       	<td align="center" valign="middle">&nbsp;</td>
       	<td colspan="2" align="center" valign="middle">&nbsp;</td>
       </tr>
       <tr>
       	<td rowspan="6" align="center" valign="middle"><p align="center">主要科学研究和教学研究工作简历</p></td>
       	<td colspan="4" align="center" valign="middle">时间</td>
       	<td colspan="2" align="center" valign="middle">项目名称</td>
       	<td align="center" valign="middle">项目来源</td>
       	<td colspan="3" align="center" valign="middle">主要鉴定意见</td>
       	<td width="64" align="center" valign="middle">获奖情况</td>
       </tr>
       <tr v-for="rRAD in searchings">
       	<td colspan="4" align="center" valign="middle">{{rRAD.searchingDateStart}}至{{rRAD.searchingDateEnd}}</td>
       	<td colspan="2" align="center" valign="middle">{{rRAD.searchingName}}</td>
       	<td align="center" valign="middle">{{rRAD.searchingSource}}</td>
       	<td colspan="3" align="center" valign="middle">&nbsp;</td>
       	<td align="center" valign="middle">{{rRAD.searchingAwards}}</td>
       </tr>
       <tr v-for="rowNumber in 5 - searchings.length">
       	<td colspan="4" align="center" valign="middle">&nbsp;</td>
       	<td colspan="2" align="center" valign="middle">&nbsp;</td>
       	<td align="center" valign="middle">&nbsp;</td>
       	<td colspan="3" align="center" valign="middle">&nbsp;</td>
       	<td align="center" valign="middle">&nbsp;</td>
       </tr>
       <tr>
       	<td rowspan="6" align="center" valign="middle">项<br />
       	目<br />
       	组<br />
       	主<br />
       	要<br />
       	成<br />
       	员</td>
       	<td align="center" valign="middle">姓名</td>
       	<td width="51" align="center" valign="middle">年龄</td>
       	<td colspan="4" align="center" valign="middle">专业技<br />
       	术职称</td>
       	<td align="center" valign="middle">职务</td>
       	<td align="center" valign="middle">所在部门</td>
       	<td colspan="2" align="center" valign="middle">主要教学<br />
       科研领域</td>
       	<td width="48" align="center" valign="middle">项目中<br />
       的分工</td>
       	<td align="center" valign="middle">签字</td>
       </tr>
       <tr v-for="mMA in members">
       	<td align="center" valign="middle">{{mMA.memberName}}</td>
       	<td colspan="2" align="center" valign="middle">{{getAge(mMA.idcard)}}</td>
       	<td colspan="3" align="center" valign="middle">{{mMA.memberTitle}}</td>
       	<td align="center" valign="middle">{{mMA.memberJob}}</td>
       	<td align="center" valign="middle">{{mMA.memberDep}}</td>
       	<td colspan="2" align="center" valign="middle">{{mMA.memberResearchareas}}</td>
       	<td align="center" valign="middle">{{mMA.memberDivision}}</td>
       	<td align="center" valign="middle"><img :src="'/img' + mMA.memberSignature.substr(6)" width="80"/></td>
       </tr>
       <tr v-for="rowNumber in 5 - members.length">
       	<td align="center" valign="middle">&nbsp;</td>
       	<td colspan="2" align="center" valign="middle">&nbsp;</td>
       	<td colspan="3" align="center" valign="middle">&nbsp;</td>
       	<td align="center" valign="middle">&nbsp;</td>
       	<td align="center" valign="middle">&nbsp;</td>
       	<td colspan="2" align="center" valign="middle">&nbsp;</td>
       	<td align="center" valign="middle">&nbsp;</td>
       	<td align="center" valign="middle">&nbsp;</td>
       </tr>
       </table>
       					<p align="left">二、项目的立项依据和目标 </p>
       <table width="650" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000">
       <tr>
       	<td width="566" height="100" align="left" valign="top">1．本项目的现状与存在问题分析（不少于500字） <br />
       	<p><span v-html="project.proAnalysis"></span></p>
       	</td>
       </tr>
       <tr>
       	<td height="102" align="left" valign="top">2．本项目的改革研究内容、主要特色和要解决的关键问题（不少于2000字）
       	<p><span v-html="project.proProblem"></span></p>
       	</td>
       </tr>
       <tr>
       	<td height="104" align="left" valign="top">3．本项目改革研究的预期成果（不少于500字）
       	<p><span v-html="project.proExpection"></span></p>
       	</td>
       </tr>
       <tr>
       	<td height="104" align="left" valign="top">4．本项目的改革研究的总体安排及进度（不少于500字）
       	<p><span v-html="project.proArrange"></span></p>
       	</td>
       </tr>
       <tr>
       	<td height="122" align="left" valign="top">5．已有的工作基础、条件及前期已有工作成果（不少于500字）
       	<p><span v-html="project.proResults"></span></p>
       	</td>
       </tr>
       </table>
       <br />
       <p align="left">三、所在单位教学工作委员会意见 </p>
       <table width="650" align="center" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">
       <tr>
       	<td align="left"><p>&nbsp;</p>
         <p><span v-html="project.proCommittee"></span></p>
       	<p>&nbsp;</p>
       	<p>&nbsp;</p>
       	<p>&nbsp;</p>
       	<p align="right">签    章 &nbsp;&nbsp;</p>
       	<p align="right">年    月    日</p></td>
       </tr>
       </table>
      <p align="left">四、学校审批意见 </p>
       <table width="650" align="center" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">
       <tr>
       	<td align="left"><p>&nbsp;</p>
         <p><span v-html="project.proSchool"></span></p>
       	<p>&nbsp;</p>
       	<p>&nbsp;</p>
       	<p>&nbsp;</p>
       	<p align="right">签    章 &nbsp;&nbsp;</p>
       	<p align="right">年    月    日</p></td>
       </tr>
       </table>

       <p align="left">五、专家审批意见 </p>
        <table width="650" align="center" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">
        <tr>
        	<td align="left"><p>&nbsp;</p>
          <p><span v-html="project.proExperts"></span></p>
        	<p>&nbsp;</p>
        	<p>&nbsp;</p>
        	<p>&nbsp;</p>
        	<p align="right">签    章 &nbsp;&nbsp;</p>
        	<p align="right">{{new Date(project.expertsDate).getFullYear() }}年{{new Date(project.expertsDate).getMonth() }}月  日</p></td>
        </tr>
        </table>

       </table>

       <!-- <table width="650" align="center" border="2" cellpadding="0" cellspacing="0" bordercolor="#000000" style="margin-top: 10px;">
       <tr>
         <div style="padding: 20px;">
           <div>
             <div style="margin-top: 30px;">
               <h2>意见填写</h2>
                 意见类型:
                 <el-radio v-model="dialogProjectInfo.proApproval" label="4">通过</el-radio>
                 <el-radio v-model="dialogProjectInfo.proApproval" label="7">不通过</el-radio>
             </div>
             <div style="margin-top: 20px;">
             	<quill-editor v-model="dialogProjectInfo.proSchool"> </quill-editor>
             </div>
           </div>
         </div>
       </tr>
       </table> -->
    </table>

    <!-- <div style="width:650px;margin: 20px auto;">
      <el-row>
        <el-col :span="12">
            <el-button type="primary" @click="dialogSubmit">提交</el-button>
        </el-col>
        <el-col :span="12">
          <div style="text-align: right;">
            <el-button type="primary" @click="SubmitAndOpenNext">提交并打开下一个</el-button>
          </div>
        </el-col>
      </el-row>
    </div> -->
  </div>
</template>

<script>
  import Quill from 'quill';
  import "quill/dist/quill.core.css";
  import "quill/dist/quill.snow.css";
  import ImageResize from 'quill-image-resize-module';
  Quill.register('modules/imageResize', ImageResize);
  export default{
    created() {
      this.proId=this.$route.query.proId
      this.BatchId=this.$route.query.batchId
      this.teacherInfo=this.$store.state.info
      this.getData()
      this.getProjectDataAxios()
      this.getNowDate()
    },
    mounted() {
    },
    methods:{
      getProjectDataAxios() {
        let that = this;
        this.$api.batch.getProjectByBatchId({
      	batchId: this.BatchId
        }).then(
          (response)=>{
      	  console.log(response)
            var tempData=response.data.data
            var result=[]
            var isfl
            for(var i = 0 ;i < tempData.length;i++ ){
              isfl=false;
              for(var j=0;j< result.length;j++){
                if(tempData[i].proId == result[j].proId){
                  isfl=true
                  break}}
              if(!isfl){
                result.push(tempData[i])
              }
              }
              console.log(result)
              this.allProjectData=result.filter((item)=>{
             return item.proDepId==this.teacherInfo.bmbh && item.ranking==1
            })
      	})
      },
      getNowDate(){
        var nowDate = new Date();
        var year = nowDate.getFullYear();
        var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1): nowDate.getMonth() + 1;
        var day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate
         .getDate();
        var dateStr = year + "-" + month + "-" + day;
        return  dateStr
      },
      dialogSubmit(){
        if(this.dialogProjectInfo.proSchool==''){
          this.$message({
            type: 'warning',
            message: '请填写学校审批意见!',
            duration: 1000,
            offset:screen.height/2-200,
            center:true,
          })
          return false
        }
        //赋值
        this.UpdateAxios()
      },
      UpdateAxios(){
          this.$api.project.updateProject({
            projectMembers:JSON.stringify(this.members) ,
            projectSearchings:JSON.stringify(this.searchings),
            projectTeachings:JSON.stringify(this.teachings),
            proId:this.proId,
            batchId:this.BatchId,
            committeeDate:this.getNowDate(),
            proApproval:this.dialogProjectInfo.proApproval,
            departmentScore:this.project.departmentScore,
            proSchool:this.dialogProjectInfo.proSchool
          })
          .then((response)=>{
            console.log(response)
          })
          //创建 记录
          this.$api.project.creatRecord({
              gh:this.teacherInfo.gh,
              name:this.teacherInfo.xm,
              proId:this.project.proId,
              state:this.dialogProjectInfo.proApproval,
              time:this.getNowFormatDate(),
              message:this.getSimpleText(this.dialogProjectInfo.proSchool)
          }).then((response)=>{
            Object.keys(this.dialogProjectInfo).forEach(key=>{this.dialogProjectInfo[key]=''})
            console.log(response)
          })
          this.$message({
          	message: "意见填写成功!",
          	type: "success",
          	offset: screen.height / 2 - 100,
          	center: true,
            duration:1000
          })
      }
      ,
      getSimpleText(html){
        var re1 = new RegExp("<.+?>","g");//匹配html标签的正则表达式，"g"是搜索匹配多个符合的内容
        var msg = html.replace(re1,'');//执行替换成空字符
        return msg;
      },
      getNowFormatDate() {
          var date = new Date();
          var seperator1 = "-";
          var seperator2 = ":";
          var month = date.getMonth() + 1;
          var strDate = date.getDate();
          if (month >= 1 && month <= 9) {
              month = "0" + month;
          }
          if (strDate >= 0 && strDate <= 9) {
              strDate = "0" + strDate;
          }
          var Hours= date.getHours()
          if (Hours >= 0 && Hours <= 9) {
              Hours = "0" + Hours;
          }

          var Minutes= date.getMinutes()
          if (Minutes >= 0 && Minutes <= 9) {
              Minutes = "0" + Minutes;
          }

          var Seconds= date.getSeconds()
          if (Seconds >= 0 && Seconds <= 9) {
              Seconds = "0" + Seconds;
          }
          var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
                  + " " + Hours + seperator2 + Minutes
                  + seperator2 + Seconds;
          return currentdate;
      },
      SubmitAndOpenNext(){
       if(this.dialogProjectInfo.proSchool==''){
         this.$message({
           type: 'warning',
           message: '请填写学校意见!',
           duration: 1000,
           offset:screen.height/2-200,
           center:true
         })
         return false
       }
      this.$api.project.updateProject({
        projectMembers:JSON.stringify(this.members) ,
        projectSearchings:JSON.stringify(this.searchings),
        projectTeachings:JSON.stringify(this.teachings),
        proId:this.proId,
        batchId:this.BatchId,
        committeeDate:this.getNowDate(),
        proApproval:this.dialogProjectInfo.proApproval,
        departmentScore:this.project.departmentScore,
        proSchool:this.dialogProjectInfo.proSchool
      })
      .then((response)=>{
        console.log(response)
      })
      //创建 记录
      this.$api.project.creatRecord({
          gh:this.teacherInfo.gh,
          name:this.teacherInfo.xm,
          proId:this.project.proId,
          state:this.dialogProjectInfo.proApproval,
          time:this.getNowFormatDate(),
          message:this.getSimpleText(this.dialogProjectInfo.proSchool)
      }).then((response)=>{
        Object.keys(this.dialogProjectInfo).forEach(key=>{this.dialogProjectInfo[key]=''})
        console.log(response)
        var index
        for(let i=0;i<this.allProjectData.length;i++){
          if(this.proId==this.allProjectData[i].proId){
            index=i+1
            break
          }
        }
        if(index>=this.allProjectData.length){
          this.$message({
            type: 'warning',
            message: '无项目!',
            duration: 2000,
            offset:screen.height/2-200,
            center:true
          })
          return
        }
        this.$router.push({path:'/uniProjectAuditPdf',query:{proId:this.allProjectData[index].proId,batchId:this.BatchId}})
        window.location.reload()
      })
      this.$message({
      	message: "意见填写成功!",
      	type: "success",
      	offset: screen.height / 2 - 100,
      	center: true,
        duration:1000
      })


      },
      checkRecord(){
          this.$router.push({path:'/depProjectAuditRecord',query:{proId:this.proId}})
      },
      goBack(){
        this.$router.push({path:'/uniSecondProjectAudit'+'?batch_id='+this.BatchId})
      },
      getData(){
        this.$api.project.getProjectById({proId:this.proId}).then((response)=>{
          console.log(response)
          this.members=response.data.data.members
          this.project=response.data.data.project
          this.searchings=response.data.data.searchings
          for(let i=0;i<this.searchings.length;i++){
              let Date=this.searchings[0].searchingDate.split('--')
              this.$set(this.searchings[i],'searchingDateStart',Date[0])
              this.$set(this.searchings[i],'searchingDateEnd',Date[1])
          }

          this.teachings=response.data.data.teachings
          for(let i=0;i<this.teachings.length;i++){
              let Date=this.teachings[0].teachingDate.split('--')
              this.$set(this.teachings[i],'teachingDateStart',Date[0])
              this.$set(this.teachings[i],'teachingDateEnd',Date[1])
          }
          this.getSex()
        })
      },
      getAge(UUserCard) {
      	let myDate = new Date();
      	let month = myDate.getMonth() + 1;
      	let day = myDate.getDate();
      	let age = myDate.getFullYear() - UUserCard.substring(6, 10) - 1;
      	if (UUserCard.substring(10, 12) < month || UUserCard.substring(10, 12) == month && UUserCard.substring(12, 14) <= day) {
      		age++;
      	}
      	return age;
      },
      getNowDate() {
      	var nowDate = new Date();
      	var year = nowDate.getFullYear();
      	var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
      	var day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
      	var dateStr = year + "-" + month+"-"+day
        return dateStr
      },
      getSex() {
      	if (parseInt(this.members[0].idcard.substr(16, 1)) % 2 == 1) {
      		this.Sex = "男"
      	} else {
      		this.Sex = "女"
      	}
      }
    },

    data(){
        return{
          dialogProjectInfo:{
            proApproval:'',
            proSchool:''
          },
          BatchId:'',
          allProjectData:[],
          proId:'',
          members:[],
          project:{},
          searchings:[],
          teachings:[],
          teacherInfo:'',
          nowDate:'',
          proAnalysis: '',
          //项目存在的问题(副文本形式)
          proProblem: '',
          //项目预期成果(副文本形式)
          proExpection: '',
          //项目总体安排及进度(副文本形式)
          proArrange: '',
          //项目已有的工作成果(副文本形式)
          proResults: '',
        }
    }
  }
</script>

<style scoped>
  #navButtonLeft{
    position: absolute;
    top:80px
  }
  #navButtonRight{
    position: absolute;
    top:80px;
    right:30px
  }
</style>
